/**
 *  @file     TableOutput.cpp
 *  @brief    Implementation of the TableOutput interface
 *
 *  @author   Franco Riberi
 *  @email    fgriberi AT gmail.com
 *
 * Contents:  Source file for remo providing TableOutput implementation.
 *
 * System:   titere: Target Ideal TEmperature Rna Expression
 * Language:  C++
 *
 * @date       April 2014
 *
 * This file is part of titere.
 *
 * Copyright (C) 2014 - Franco Riberi, FuDePAN.
 *
 * titere is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * titere is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with titere. If not, see <http:www.gnu.org/licenses/>.
 *
 */

#include <mili/mili.h>
#include "titere/TableOutput.h"
#include "titere/Exceptions.h"

namespace NSTitere
{

TableOutput::TableOutput(const std::string& tableName)
{
    _oFile.open(tableName.c_str());
    if (_oFile.is_open())
    {
        generateHeader();
    }
}

TableOutput::~TableOutput()
{
    _oFile.close();
}

void TableOutput::generateHeader()
{
    _oFile << "Sequence, ";
    _oFile << "Position, ";
    _oFile << "Temperature, ";
    _oFile << "#unpaired, ";
    _oFile << "#unpaired2-8, ";
    _oFile << "Comparison" << std::endl;

}

void TableOutput::save(const std::string& seqName, const Position pos, const Temperature temp, const NucleotidsAmount unpairedAmount,
                       const NucleotidsAmount headUnpaired, const SequenceResult& sequence)
{
    mili::assert_throw<FileNotOpened>(_oFile.is_open());
    _oFile << seqName << ", ";
    _oFile << pos << ", ";
    _oFile << temp << ", ";
    _oFile << unpairedAmount << ", ";
    _oFile << headUnpaired << ", ";
    _oFile << sequence << std::endl;
}

} // namespace NSTitere